# UNHCR Flow Data
# Author: Connor Kelly
# Date: Dec 2, 2020
library(readxl)
library(tidyverse)
library(plotly)
# Set Parameters (feel free to change)
startyear <- "1962" # specifies which year we want to start our observations (MIN: 1962, MAX: 2018)
n <- 10 # specifies # of top destinations to display
I am analyzing data from UNHCR to understand the flows of asylum seekers and refugees from country to country.
First, I do some initial setup work. My main goals here are to clean the data for easier use, replacing missing values as zero, create new variables, and rearrange the dataset in a way that allows for easier analysis later on.
setwd("C:/Users/Connor/Documents/GitHub/MDI")
flow <- read_excel("Data/new_ref_arrival_new_asy_app_1962_2019.xlsx", skip = 1)
flow[is.na(flow)] <- 0 # Replace missing values as 0
# Start by looking at origin
flow_origin <- flow %>% # Aggregate by country origin
group_by(`Origin`, `Population type`) %>%
summarise_if(is.numeric, sum)
flow_sum <- flow_origin %>% # Create new population type "total" equal to sum of asylum seekers and refugees from given country of origin
group_by(`Origin`) %>%
summarise_if(is.numeric, sum)
flow_sum$`Population type` <- "Total" # Specify population type name
flow_sum <- flow_sum[,c(1, 60, 2:59)] # Reorder to standard format
flow_origin <- bind_rows(flow_origin, flow_sum) # Add total to original dataframe
# Priority Countries
origin <- data.frame(t(flow_sum)) # Transpose dataframe for ease of use
colnames(origin) <- flow_sum$Origin # Change column names to countries
origin <- origin[-c(1,2),] # Remove redundant rows
origin$year <- rownames(origin) # change row names to years
origin$year <- as.numeric(origin$year) # Create year variable
origin <- origin[c(231, 1:230)] # Bring year variable to front
origin[, 1:231] <- sapply(origin[, 1:231], as.character) # Convert data to numeric
# Unclear why I need to first convert from factor to character and THEN character to numeric but this works
origin[, 1:231] <- sapply(origin[, 1:231], as.numeric)
Next, I generate plots of the number of asylum seekers and refugees fleeing a given country over time. The R package “plotly” generates interactive plots which make it easier to pinpoint specific observations over time. You can hover your cursor over the graph to see the precise number of refugees and asylum seekers in a given year. You can also zoom in or highlight specific periods of interest.
afg_p <- ggplot(origin, aes(year, Afghanistan)) + geom_line() + ggtitle("Refugees and Aylum Seekers from Afghanistan") +
ylab("Refugees and Asylum Seekers") + xlab("Year")
ggplotly(afg_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
bgd_p <- ggplot(origin, aes(year, Bangladesh)) + geom_line() + ggtitle("Refugees and Aylum Seekers from Afghanistan") +
ylab("Refugees and Asylum Seekers") + xlab("Year")
ggplotly(bgd_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
bdi_p <- ggplot(origin, aes(year, Burundi)) + geom_line() + ggtitle("Refugees and Aylum Seekers from Burundi") +
ylab("Refugees and Asylum Seekers") + xlab("Year")
ggplotly(bdi_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
caf_p <- ggplot(origin, aes(year, `Central African Rep.`)) + geom_line() +
ggtitle("Refugees and Aylum Seekers from Central African Republic") + ylab("Refugees and Asylum Seekers") + xlab("Year")
ggplotly(caf_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
tcd_p <- ggplot(origin, aes(year, Chad)) + geom_line() + ggtitle("Refugees and Aylum Seekers from Chad") +
ylab("Refugees and Asylum Seekers") + xlab("Year")
ggplotly(tcd_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
### Ethiopia
eth_p <- ggplot(origin, aes(year, Ethiopia)) + geom_line() + ggtitle("Refugees and Aylum Seekers from Ethiopia") +
ylab("Refugees and Asylum Seekers") + xlab("Year")
ggplotly(eth_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
gtm_p <- ggplot(origin, aes(year, Guatemala)) + geom_line() + ggtitle("Refugees and Aylum Seekers from Guatemala") +
ylab("Refugees and Asylum Seekers") + xlab("Year")
ggplotly(gtm_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
irq_p <- ggplot(origin, aes(year, Iraq)) + geom_line() + ggtitle("Refugees and Aylum Seekers from Iraq") +
ylab("Refugees and Asylum Seekers") + xlab("Year")
ggplotly(irq_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
lby_p <- ggplot(origin, aes(year, Libya)) + geom_line() + ggtitle("Refugees and Aylum Seekers from Libya") +
ylab("Refugees and Asylum Seekers") + xlab("Year")
ggplotly(lby_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
mli_p <- ggplot(origin, aes(year, Mali)) + geom_line() + ggtitle("Refugees and Aylum Seekers from Mali") +
ylab("Refugees and Asylum Seekers") + xlab("Year")
ggplotly(mli_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
mmr_p <- ggplot(origin, aes(year, Myanmar)) + geom_line() + ggtitle("Refugees and Aylum Seekers from Myanmar") +
ylab("Refugees and Asylum Seekers") + xlab("Year")
ggplotly(mmr_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
nga_p <- ggplot(origin, aes(year, Nigeria)) + geom_line() + ggtitle("Refugees and Aylum Seekers from Nigeria") +
ylab("Refugees and Asylum Seekers") + xlab("Year")
ggplotly(nga_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
som_p <- ggplot(origin, aes(year, Somalia)) + geom_line() + ggtitle("Refugees and Aylum Seekers from Somalia") +
ylab("Refugees and Asylum Seekers") + xlab("Year")
ggplotly(som_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
ssd_p <- ggplot(origin, aes(year, `South Sudan`)) + geom_line() + ggtitle("Refugees and Aylum Seekers from South Sudan") +
ylab("Refugees and Asylum Seekers") + xlab("Year")
ggplotly(ssd_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
sdn_p <- ggplot(origin, aes(year, Sudan)) + geom_line() + ggtitle("Refugees and Aylum Seekers from Sudan") +
ylab("Refugees and Asylum Seekers") + xlab("Year")
ggplotly(sdn_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
syr_p <- ggplot(origin, aes(year, `Syrian Arab Rep.`)) + geom_line() + ggtitle("Refugees and Aylum Seekers from Syria") +
ylab("Refugees and Asylum Seekers") + xlab("Year")
ggplotly(syr_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
ven_p <- ggplot(origin, aes(year, `Venezuela (Bolivarian Republic of)`)) + geom_line() +
ggtitle("Refugees and Aylum Seekers from Venezuela") + ylab("Refugees and Asylum Seekers") + xlab("Year")
ggplotly(ven_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
yem_p <- ggplot(origin, aes(year, Yemen)) + geom_line() + ggtitle("Refugees and Aylum Seekers from Yemen") +
ylab("Refugees and Asylum Seekers") + xlab("Year")
ggplotly(yem_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
Next, I want to see where exactly asylum seekers from these priority countries are going. For each country of interest, I disaggregate my data based on country of asylum (i.e. to where have asylum seekers fled). I then plot the number of asylum seekers in each country of asylum over time. This makes for a busy plot, but the Plotly package makes this more managable. If you wish to toggle whether a certain country is shown on the plot, you can click on the country name in the legend. If you wish to isolate the graph to show only one country, double click on that country in the legend.
afg <- flow %>%
filter(Origin == "Afghanistan") %>%
group_by(`Country of asylum`) %>%
summarize_if(is.numeric, sum)
afg <- pivot_longer(afg, # Make wide data long for easier plotting
cols = c(startyear:59),
names_to = "year",
values_to = "asylumseekers")
## Note: Using an external vector in selections is ambiguous.
## i Use `all_of(startyear)` instead of `startyear` to silence this message.
## i See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
## This message is displayed once per session.
top <- afg %>% group_by(`Country of asylum`) %>% # Identify top destinations
summarize(total = sum(asylumseekers)) %>%
arrange(desc(total))
top <- head(top$`Country of asylum`, n=n) # save top destinations as string
afg <- afg %>% filter(`Country of asylum` %in% top) # Only include top destinations
afg$year <- as.numeric(afg$year)
afg$`Country of asylum` <- factor(afg$`Country of asylum`, levels = top) # Sort by top destinations
afg_p <- ggplot(afg, aes(x=year, y=asylumseekers, color=`Country of asylum`)) + geom_line() +
ggtitle("Top Destinations of Afghan Refugees and Asylum Seeekers") + xlab("Year") + ylab("Refugees and Asylum Seekers")
ggplotly(afg_p, dynamicTicks = TRUE)
bgd <- flow %>%
filter(Origin == "Bangladesh") %>%
group_by(`Country of asylum`) %>%
summarize_if(is.numeric, sum)
bgd <- pivot_longer(bgd, # Make wide data long for easier plotting
cols = c(startyear:59),
names_to = "year",
values_to = "asylumseekers")
top <- bgd %>% group_by(`Country of asylum`) %>% # Identify top destinations
summarize(total = sum(asylumseekers)) %>%
arrange(desc(total))
top <- head(top$`Country of asylum`, n=n) # save top destinations as string
bgd <- bgd %>% filter(`Country of asylum` %in% top) # Only include top destinations
bgd$year <- as.numeric(bgd$year)
bgd$`Country of asylum` <- factor(bgd$`Country of asylum`, levels = top) # Sort by top destinations
bgd_p <- ggplot(bgd, aes(x=year, y=asylumseekers, color=`Country of asylum`)) + geom_line() +
ggtitle("Top Destinations of Bangladeshi Refugees and Asylum Seeekers") + xlab("Year") + ylab("Refugees and Asylum Seekers")
ggplotly(bgd_p, dynamicTicks = TRUE)
bdi <- flow %>%
filter(Origin == "Burundi") %>%
group_by(`Country of asylum`) %>%
summarize_if(is.numeric, sum)
bdi <- pivot_longer(bdi, # Make wide data long for easier plotting
cols = c(startyear:59),
names_to = "year",
values_to = "asylumseekers")
top <- bdi %>% group_by(`Country of asylum`) %>% # Identify top destinations
summarize(total = sum(asylumseekers)) %>%
arrange(desc(total))
top <- head(top$`Country of asylum`, n=n) # save top destinations as string
bdi <- bdi %>% filter(`Country of asylum` %in% top) # Only include top destinations
bdi$year <- as.numeric(bdi$year)
bdi$`Country of asylum` <- factor(bdi$`Country of asylum`, levels = top) # Sort by top destinations
bdi_p <- ggplot(bdi, aes(x=year, y=asylumseekers, color=`Country of asylum`)) + geom_line() +
ggtitle("Top Destinations of Burundian Refugees and Asylum Seeekers") + xlab("Year") + ylab("Refugees and Asylum Seekers")
ggplotly(bdi_p, dynamicTicks = TRUE)
caf <- flow %>%
filter(Origin == "Central African Rep.") %>%
group_by(`Country of asylum`) %>%
summarize_if(is.numeric, sum)
caf <- pivot_longer(caf, # Make wide data long for easier plotting
cols = c(startyear:59),
names_to = "year",
values_to = "asylumseekers")
top <- caf %>% group_by(`Country of asylum`) %>% # Identify top destinations
summarize(total = sum(asylumseekers)) %>%
arrange(desc(total))
top <- head(top$`Country of asylum`, n=n) # save top destinations as string
caf <- caf %>% filter(`Country of asylum` %in% top) # Only include top destinations
caf$year <- as.numeric(caf$year)
caf$`Country of asylum` <- factor(caf$`Country of asylum`, levels = top) # Sort by top destinations
caf_p <- ggplot(caf, aes(x=year, y=asylumseekers, color=`Country of asylum`)) + geom_line() +
ggtitle("Top Destinations of Central African Refugees and Asylum Seeekers") + xlab("Year") + ylab("Refugees and Asylum Seekers")
ggplotly(caf_p, dynamicTicks = TRUE)
tcd <- flow %>%
filter(Origin == "Chad") %>%
group_by(`Country of asylum`) %>%
summarize_if(is.numeric, sum)
tcd <- pivot_longer(tcd, # Make wide data long for easier plotting
cols = c(startyear:59),
names_to = "year",
values_to = "asylumseekers")
top <- tcd %>% group_by(`Country of asylum`) %>% # Identify top destinations
summarize(total = sum(asylumseekers)) %>%
arrange(desc(total))
top <- head(top$`Country of asylum`, n=n) # save top destinations as string
tcd <- tcd %>% filter(`Country of asylum` %in% top) # Only include top destinations
tcd$year <- as.numeric(tcd$year)
tcd$`Country of asylum` <- factor(tcd$`Country of asylum`, levels = top) # Sort by top destinations
tcd_p <- ggplot(tcd, aes(x=year, y=asylumseekers, color=`Country of asylum`)) + geom_line() +
ggtitle("Top Destinations of Chadian Refugees and Asylum Seeekers") + xlab("Year") + ylab("Refugees and Asylum Seekers")
ggplotly(tcd_p, dynamicTicks = TRUE)
eth <- flow %>%
filter(Origin == "Ethiopia") %>%
group_by(`Country of asylum`) %>%
summarize_if(is.numeric, sum)
eth <- pivot_longer(eth, # Make wide data long for easier plotting
cols = c(startyear:59),
names_to = "year",
values_to = "asylumseekers")
top <- eth %>% group_by(`Country of asylum`) %>% # Identify top destinations
summarize(total = sum(asylumseekers)) %>%
arrange(desc(total))
top <- head(top$`Country of asylum`, n=n) # save top destinations as string
eth <- eth %>% filter(`Country of asylum` %in% top) # Only include top destinations
eth$year <- as.numeric(eth$year)
eth$`Country of asylum` <- factor(eth$`Country of asylum`, levels = top) # Sort by top destinations
eth_p <- ggplot(eth, aes(x=year, y=asylumseekers, color=`Country of asylum`)) + geom_line() +
ggtitle("Top Destinations of Ethiopian Refugees and Asylum Seeekers") + xlab("Year") + ylab("Refugees and Asylum Seekers")
ggplotly(eth_p, dynamicTicks = TRUE)
gtm <- flow %>%
filter(Origin == "Guatemala") %>%
group_by(`Country of asylum`) %>%
summarize_if(is.numeric, sum)
gtm <- pivot_longer(gtm, # Make wide data long for easier plotting
cols = c(startyear:59),
names_to = "year",
values_to = "asylumseekers")
top <- gtm %>% group_by(`Country of asylum`) %>% # Identify top destinations
summarize(total = sum(asylumseekers)) %>%
arrange(desc(total))
top <- head(top$`Country of asylum`, n=n) # save top destinations as string
gtm <- gtm %>% filter(`Country of asylum` %in% top) # Only include top destinations
gtm$year <- as.numeric(gtm$year)
gtm$`Country of asylum` <- factor(gtm$`Country of asylum`, levels = top) # Sort by top destinations
gtm_p <- ggplot(gtm, aes(x=year, y=asylumseekers, color=`Country of asylum`)) + geom_line() +
ggtitle("Top Destinations of Guatemalan Refugees and Asylum Seeekers") + xlab("Year") + ylab("Refugees and Asylum Seekers")
ggplotly(gtm_p, dynamicTicks = TRUE)
irq <- flow %>%
filter(Origin == "Iraq") %>%
group_by(`Country of asylum`) %>%
summarize_if(is.numeric, sum)
irq <- pivot_longer(irq, # Make wide data long for easier plotting
cols = c(startyear:59),
names_to = "year",
values_to = "asylumseekers")
top <- irq %>% group_by(`Country of asylum`) %>% # Identify top destinations
summarize(total = sum(asylumseekers)) %>%
arrange(desc(total))
top <- head(top$`Country of asylum`, n=n) # save top destinations as string
irq <- irq %>% filter(`Country of asylum` %in% top) # Only include top destinations
irq$year <- as.numeric(irq$year)
irq$`Country of asylum` <- factor(irq$`Country of asylum`, levels = top) # Sort by top destinations
irq_p <- ggplot(irq, aes(x=year, y=asylumseekers, color=`Country of asylum`)) + geom_line() +
ggtitle("Top Destinations of Iraqi Refugees and Asylum Seeekers") + xlab("Year") + ylab("Refugees and Asylum Seekers")
ggplotly(irq_p, dynamicTicks = TRUE)
lby <- flow %>%
filter(Origin == "Libya") %>%
group_by(`Country of asylum`) %>%
summarize_if(is.numeric, sum)
lby <- pivot_longer(lby, # Make wide data long for easier plotting
cols = c(startyear:59),
names_to = "year",
values_to = "asylumseekers")
top <- lby %>% group_by(`Country of asylum`) %>% # Identify top destinations
summarize(total = sum(asylumseekers)) %>%
arrange(desc(total))
top <- head(top$`Country of asylum`, n=n) # save top destinations as string
lby <- lby %>% filter(`Country of asylum` %in% top) # Only include top destinations
lby$year <- as.numeric(lby$year)
lby$`Country of asylum` <- factor(lby$`Country of asylum`, levels = top) # Sort by top destinations
lby_p <- ggplot(lby, aes(x=year, y=asylumseekers, color=`Country of asylum`)) + geom_line() +
ggtitle("Top Destinations of Libyan Refugees and Asylum Seeekers") + xlab("Year") + ylab("Refugees and Asylum Seekers")
ggplotly(lby_p, dynamicTicks = TRUE)
mli <- flow %>%
filter(Origin == "Mali") %>%
group_by(`Country of asylum`) %>%
summarize_if(is.numeric, sum)
mli <- pivot_longer(mli, # Make wide data long for easier plotting
cols = c(startyear:59),
names_to = "year",
values_to = "asylumseekers")
top <- mli %>% group_by(`Country of asylum`) %>% # Identify top destinations
summarize(total = sum(asylumseekers)) %>%
arrange(desc(total))
top <- head(top$`Country of asylum`, n=n) # save top destinations as string
mli <- mli %>% filter(`Country of asylum` %in% top) # Only include top destinations
mli$year <- as.numeric(mli$year)
mli$`Country of asylum` <- factor(mli$`Country of asylum`, levels = top) # Sort by top destinations
mli_p <- ggplot(mli, aes(x=year, y=asylumseekers, color=`Country of asylum`)) + geom_line() +
ggtitle("Top Destinations of Malian Refugees and Asylum Seeekers") + xlab("Year") + ylab("Refugees and Asylum Seekers")
ggplotly(mli_p, dynamicTicks = TRUE)
mmr <- flow %>%
filter(Origin == "Myanmar") %>%
group_by(`Country of asylum`) %>%
summarize_if(is.numeric, sum)
mmr <- pivot_longer(mmr, # Make wide data long for easier plotting
cols = c(startyear:59),
names_to = "year",
values_to = "asylumseekers")
top <- mmr %>% group_by(`Country of asylum`) %>% # Identify top destinations
summarize(total = sum(asylumseekers)) %>%
arrange(desc(total))
top <- head(top$`Country of asylum`, n=n) # save top destinations as string
mmr <- mmr %>% filter(`Country of asylum` %in% top) # Only include top destinations
mmr$year <- as.numeric(mmr$year)
mmr$`Country of asylum` <- factor(mmr$`Country of asylum`, levels = top) # Sort by top destinations
mmr_p <- ggplot(mmr, aes(x=year, y=asylumseekers, color=`Country of asylum`)) + geom_line() +
ggtitle("Top Destinations of Burmese Refugees and Asylum Seeekers") + xlab("Year") + ylab("Refugees and Asylum Seekers")
ggplotly(mmr_p, dynamicTicks = TRUE)
nga <- flow %>%
filter(Origin == "Nigeria") %>%
group_by(`Country of asylum`) %>%
summarize_if(is.numeric, sum)
nga <- pivot_longer(nga, # Make wide data long for easier plotting
cols = c(startyear:59),
names_to = "year",
values_to = "asylumseekers")
top <- nga %>% group_by(`Country of asylum`) %>% # Identify top destinations
summarize(total = sum(asylumseekers)) %>%
arrange(desc(total))
top <- head(top$`Country of asylum`, n=n) # save top destinations as string
nga <- nga %>% filter(`Country of asylum` %in% top) # Only include top destinations
nga$year <- as.numeric(nga$year)
nga$`Country of asylum` <- factor(nga$`Country of asylum`, levels = top) # Sort by top destinations
nga_p <- ggplot(nga, aes(x=year, y=asylumseekers, color=`Country of asylum`)) + geom_line() +
ggtitle("Top Destinations of Nigerian Refugees and Asylum Seeekers") + xlab("Year") + ylab("Refugees and Asylum Seekers")
ggplotly(nga_p, dynamicTicks = TRUE)
som <- flow %>%
filter(Origin == "Somalia") %>%
group_by(`Country of asylum`) %>%
summarize_if(is.numeric, sum)
som <- pivot_longer(som, # Make wide data long for easier plotting
cols = c(startyear:59),
names_to = "year",
values_to = "asylumseekers")
top <- som %>% group_by(`Country of asylum`) %>% # Identify top destinations
summarize(total = sum(asylumseekers)) %>%
arrange(desc(total))
top <- head(top$`Country of asylum`, n=n) # save top destinations as string
som <- som %>% filter(`Country of asylum` %in% top) # Only include top destinations
som$year <- as.numeric(som$year)
som$`Country of asylum` <- factor(som$`Country of asylum`, levels = top) # Sort by top destinations
som_p <- ggplot(som, aes(x=year, y=asylumseekers, color=`Country of asylum`)) + geom_line() +
ggtitle("Top Destinations of Somali Refugees and Asylum Seeekers") + xlab("Year") + ylab("Refugees and Asylum Seekers")
ggplotly(som_p, dynamicTicks = TRUE)
ssd <- flow %>%
filter(Origin == "South Sudan") %>%
group_by(`Country of asylum`) %>%
summarize_if(is.numeric, sum)
ssd <- pivot_longer(ssd, # Make wide data long for easier plotting
cols = c(startyear:59),
names_to = "year",
values_to = "asylumseekers")
top <- ssd %>% group_by(`Country of asylum`) %>% # Identify top destinations
summarize(total = sum(asylumseekers)) %>%
arrange(desc(total))
top <- head(top$`Country of asylum`, n=n) # save top destinations as string
ssd <- ssd %>% filter(`Country of asylum` %in% top) # Only include top destinations
ssd$year <- as.numeric(ssd$year)
ssd$`Country of asylum` <- factor(ssd$`Country of asylum`, levels = top) # Sort by top destinations
ssd_p <- ggplot(ssd, aes(x=year, y=asylumseekers, color=`Country of asylum`)) + geom_line() +
ggtitle("Top Destinations of South Sudanese Refugees and Asylum Seeekers") + xlab("Year") + ylab("Refugees and Asylum Seekers")
ggplotly(ssd_p, dynamicTicks = TRUE)
sdn <- flow %>%
filter(Origin == "Sudan") %>%
group_by(`Country of asylum`) %>%
summarize_if(is.numeric, sum)
sdn <- pivot_longer(sdn, # Make wide data long for easier plotting
cols = c(startyear:59),
names_to = "year",
values_to = "asylumseekers")
top <- sdn %>% group_by(`Country of asylum`) %>% # Identify top destinations
summarize(total = sum(asylumseekers)) %>%
arrange(desc(total))
top <- head(top$`Country of asylum`, n=n) # save top destinations as string
sdn <- sdn %>% filter(`Country of asylum` %in% top) # Only include top destinations
sdn$year <- as.numeric(sdn$year)
sdn$`Country of asylum` <- factor(sdn$`Country of asylum`, levels = top) # Sort by top destinations
sdn_p <- ggplot(sdn, aes(x=year, y=asylumseekers, color=`Country of asylum`)) + geom_line() +
ggtitle("Top Destinations of Sudanese Refugees and Asylum Seeekers") + xlab("Year") + ylab("Refugees and Asylum Seekers")
ggplotly(sdn_p, dynamicTicks = TRUE)
syr <- flow %>%
filter(Origin == "Syrian Arab Rep.") %>%
group_by(`Country of asylum`) %>%
summarize_if(is.numeric, sum)
syr <- pivot_longer(syr, # Make wide data long for easier plotting
cols = c(startyear:59),
names_to = "year",
values_to = "asylumseekers")
top <- syr %>% group_by(`Country of asylum`) %>% # Identify top destinations
summarize(total = sum(asylumseekers)) %>%
arrange(desc(total))
top <- head(top$`Country of asylum`, n=n) # save top destinations as string
syr <- syr %>% filter(`Country of asylum` %in% top) # Only include top destinations
syr$year <- as.numeric(syr$year)
syr$`Country of asylum` <- factor(syr$`Country of asylum`, levels = top) # Sort by top destinations
syr_p <- ggplot(syr, aes(x=year, y=asylumseekers, color=`Country of asylum`)) + geom_line() +
ggtitle("Top Destinations of Syrian Refugees and Asylum Seeekers") + xlab("Year") + ylab("Refugees and Asylum Seekers")
ggplotly(syr_p, dynamicTicks = TRUE)
ven <- flow %>%
filter(Origin == "Venezuela (Bolivarian Republic of)") %>%
group_by(`Country of asylum`) %>%
summarize_if(is.numeric, sum)
ven <- pivot_longer(ven, # Make wide data long for easier plotting
cols = c(startyear:59),
names_to = "year",
values_to = "asylumseekers")
top <- ven %>% group_by(`Country of asylum`) %>% # Identify top destinations
summarize(total = sum(asylumseekers)) %>%
arrange(desc(total))
top <- head(top$`Country of asylum`, n=n) # save top destinations as string
ven <- ven %>% filter(`Country of asylum` %in% top) # Only include top destinations
ven$year <- as.numeric(ven$year)
ven$`Country of asylum` <- factor(ven$`Country of asylum`, levels = top) # Sort by top destinations
ven_p <- ggplot(ven, aes(x=year, y=asylumseekers, color=`Country of asylum`)) + geom_line() +
ggtitle("Top Destinations of Venezuelan Refugees and Asylum Seeekers") + xlab("Year") + ylab("Refugees and Asylum Seekers")
ggplotly(ven_p, dynamicTicks = TRUE)
yem <- flow %>%
filter(Origin == "Yemen") %>%
group_by(`Country of asylum`) %>%
summarize_if(is.numeric, sum)
yem <- pivot_longer(yem, # Make wide data long for easier plotting
cols = c(startyear:59),
names_to = "year",
values_to = "asylumseekers")
top <- yem %>% group_by(`Country of asylum`) %>% # Identify top destinations
summarize(total = sum(asylumseekers)) %>%
arrange(desc(total))
top <- head(top$`Country of asylum`, n=n) # save top destinations as string
yem <- yem %>% filter(`Country of asylum` %in% top) # Only include top destinations
yem$year <- as.numeric(yem$year)
yem$`Country of asylum` <- factor(yem$`Country of asylum`, levels = top) # Sort by top destinations
yem_p <- ggplot(yem, aes(x=year, y=asylumseekers, color=`Country of asylum`)) + geom_line() +
ggtitle("Top Destinations of Yemeni Refugees and Asylum Seeekers") + xlab("Year") + ylab("Refugees and Asylum Seekers")
ggplotly(yem_p, dynamicTicks = TRUE)
# UNHCR Demographics
# Author: Connor Kelly
# Date: December 1, 2020
library(tidyverse)
library(plotly)
setwd("C:/Users/Connor/Documents/GitHub/MDI")
# Import Data
agesex <- read_csv("Data/unhcr_popstats_export_demographics_all_data.csv",
skip = 3) # Date extracted: 2015-09-18 04:37:44 +02:00 (update?)
## Warning: 48820 parsing failures.
## row col expected actual file
## 3230 Female 5-11 1/0/T/F/TRUE/FALSE 88 'Data/unhcr_popstats_export_demographics_all_data.csv'
## 3230 Female 12-17 1/0/T/F/TRUE/FALSE 45 'Data/unhcr_popstats_export_demographics_all_data.csv'
## 3230 Male 5-11 1/0/T/F/TRUE/FALSE 115 'Data/unhcr_popstats_export_demographics_all_data.csv'
## 3230 Male 12-17 1/0/T/F/TRUE/FALSE 38 'Data/unhcr_popstats_export_demographics_all_data.csv'
## 3231 Female 5-11 1/0/T/F/TRUE/FALSE 139 'Data/unhcr_popstats_export_demographics_all_data.csv'
## .... ............ .................. ...... ......................................................
## See problems(...) for more details.
# Examine Data
agesex[is.na(agesex)] <- 0 # Replace missing values as 0
str(agesex) # Both Male and Female 5-11 and 12-17 are logical rather than numeric
## Classes 'spec_tbl_df', 'tbl_df', 'tbl' and 'data.frame': 19869 obs. of 19 variables:
## $ Year : num 2001 2001 2001 2001 2001 ...
## $ Country / territory of asylum/residence: chr "Afghanistan" "Afghanistan" "Afghanistan" "Angola" ...
## $ Location Name : chr "Kabul" "Various" "Herat" "Viana" ...
## $ Female 0-4 : num 0 14335 0 484 219 ...
## $ Female 5-11 : num 0 0 0 0 0 0 0 0 0 0 ...
## $ Female 5-17 : num 1 45451 0 1687 734 ...
## $ Female 12-17 : num 0 0 0 0 0 0 0 0 0 0 ...
## $ Female 18-59 : num 1 99880 1 1282 427 ...
## $ Female 60+ : num 0 19234 0 43 25 ...
## $ F: Unknown : num 0 412004 0 0 0 ...
## $ F: Total : num 2 590904 1 3496 1405 ...
## $ Male 0-4 : num 0 14716 0 597 226 ...
## $ Male 5-11 : num 0 0 0 0 0 0 0 0 0 0 ...
## $ Male 5-17 : num 0 47522 0 1645 711 ...
## $ Male 12-17 : num 0 0 0 0 0 0 0 0 0 0 ...
## $ Male 18-59 : num 2 114965 1 787 139 ...
## $ Male 60+ : num 0 13025 0 34 15 ...
## $ M: Unknown : num 0 435492 0 0 0 ...
## $ M: Total : num 2 625720 1 3063 1091 ...
## - attr(*, "problems")=Classes 'tbl_df', 'tbl' and 'data.frame': 48820 obs. of 5 variables:
## ..$ row : int 3230 3230 3230 3230 3231 3231 3231 3231 3232 3232 ...
## ..$ col : chr "Female 5-11" "Female 12-17" "Male 5-11" "Male 12-17" ...
## ..$ expected: chr "1/0/T/F/TRUE/FALSE" "1/0/T/F/TRUE/FALSE" "1/0/T/F/TRUE/FALSE" "1/0/T/F/TRUE/FALSE" ...
## ..$ actual : chr "88" "45" "115" "38" ...
## ..$ file : chr "'Data/unhcr_popstats_export_demographics_all_data.csv'" "'Data/unhcr_popstats_export_demographics_all_data.csv'" "'Data/unhcr_popstats_export_demographics_all_data.csv'" "'Data/unhcr_popstats_export_demographics_all_data.csv'" ...
## - attr(*, "spec")=
## .. cols(
## .. Year = col_double(),
## .. `Country / territory of asylum/residence` = col_character(),
## .. `Location Name` = col_character(),
## .. `Female 0-4` = col_double(),
## .. `Female 5-11` = col_logical(),
## .. `Female 5-17` = col_double(),
## .. `Female 12-17` = col_logical(),
## .. `Female 18-59` = col_double(),
## .. `Female 60+` = col_double(),
## .. `F: Unknown` = col_double(),
## .. `F: Total` = col_double(),
## .. `Male 0-4` = col_double(),
## .. `Male 5-11` = col_logical(),
## .. `Male 5-17` = col_double(),
## .. `Male 12-17` = col_logical(),
## .. `Male 18-59` = col_double(),
## .. `Male 60+` = col_double(),
## .. `M: Unknown` = col_double(),
## .. `M: Total` = col_double()
## .. )
agesex = subset(agesex, select=-c(`Female 5-11`, `Female 12-17`, `F: Total`, `Male 5-11`, `Male 12-17`, `M: Total`)) # Drop logical columns and totals
# Aggregate by country of asylum
agesex <- agesex %>%
group_by(Year, `Country / territory of asylum/residence`) %>%
summarize_if(is.numeric, sum)
# Establish color palette for plots
colors <- c( "#FB6A4A", "#EF3B2C", "#CB181D", "#A50F15", "#67000D", # red palette (female)
"#6BAED6", "#4292C6", "#2171B5", "#08519C", "#08306B") # blue palette (male)
This data shows the age and sex disaggregated breakdown of refugees and asylum seekers residing in the given countries of asylum. It is important to note that this data focuses on the country of residence of refugees and asylum seekers, not their country of origin.
afg <- agesex %>% filter(`Country / territory of asylum/residence`=="Afghanistan")
afg <- pivot_longer(afg,
cols = c(3:12),
names_to = "agesex",
values_to = "refugees")
afg$agesex <- factor(afg$agesex, levels = c("Female 0-4", "Female 5-17", "Female 18-59", "Female 60+", "F: Unknown",
"Male 0-4", "Male 5-17", "Male 18-59", "Male 60+", "M: Unknown"))
afg_p <- ggplot(afg, aes(x=Year, y=refugees, fill=agesex)) + geom_area() + scale_fill_manual(values = colors) +
ggtitle("Age and Sex of Displaced in Afghanistan") + ylab("Refugees and Asylum Seekers") + theme(legend.title = element_blank())
ggplotly(afg_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
bgd <- agesex %>% filter(`Country / territory of asylum/residence`=="Bangladesh")
bgd <- pivot_longer(bgd,
cols = c(3:12),
names_to = "agesex",
values_to = "refugees")
bgd$agesex <- factor(bgd$agesex, levels = c("Female 0-4", "Female 5-17", "Female 18-59", "Female 60+", "F: Unknown",
"Male 0-4", "Male 5-17", "Male 18-59", "Male 60+", "M: Unknown"))
bgd_p <- ggplot(bgd, aes(x=Year, y=refugees, fill=agesex)) + geom_area() + scale_fill_manual(values = colors) +
ggtitle("Age and Sex of Displaced in Bangladesh") + ylab("Refugees and Asylum Seekers") + theme(legend.title = element_blank())
ggplotly(bgd_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
bdi <- agesex %>% filter(`Country / territory of asylum/residence`=="Burundi")
bdi <- pivot_longer(bdi,
cols = c(3:12),
names_to = "agesex",
values_to = "refugees")
bdi$agesex <- factor(bdi$agesex, levels = c("Female 0-4", "Female 5-17", "Female 18-59", "Female 60+", "F: Unknown",
"Male 0-4", "Male 5-17", "Male 18-59", "Male 60+", "M: Unknown"))
bdi_p <- ggplot(bdi, aes(x=Year, y=refugees, fill=agesex)) + geom_area() + scale_fill_manual(values = colors) +
ggtitle("Age and Sex of Displaced in Burundi") + ylab("Refugees and Asylum Seekers") + theme(legend.title = element_blank())
ggplotly(bdi_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
caf <- agesex %>% filter(`Country / territory of asylum/residence`=="Central African Rep.")
caf <- pivot_longer(caf,
cols = c(3:12),
names_to = "agesex",
values_to = "refugees")
caf$agesex <- factor(caf$agesex, levels = c("Female 0-4", "Female 5-17", "Female 18-59", "Female 60+", "F: Unknown",
"Male 0-4", "Male 5-17", "Male 18-59", "Male 60+", "M: Unknown"))
caf_p <- ggplot(bdi, aes(x=Year, y=refugees, fill=agesex)) + geom_area() + scale_fill_manual(values = colors) +
ggtitle("Age and Sex of Displaced in Central African Republic") + ylab("Refugees and Asylum Seekers") + theme(legend.title = element_blank())
ggplotly(caf_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
tcd <- agesex %>% filter(`Country / territory of asylum/residence`=="Chad")
tcd <- pivot_longer(tcd,
cols = c(3:12),
names_to = "agesex",
values_to = "refugees")
tcd$agesex <- factor(tcd$agesex, levels = c("Female 0-4", "Female 5-17", "Female 18-59", "Female 60+", "F: Unknown",
"Male 0-4", "Male 5-17", "Male 18-59", "Male 60+", "M: Unknown"))
tcd_p <- ggplot(tcd, aes(x=Year, y=refugees, fill=agesex)) + geom_area() + scale_fill_manual(values = colors) +
ggtitle("Age and Sex of Displaced in Chad") + ylab("Refugees and Asylum Seekers") + theme(legend.title = element_blank())
ggplotly(tcd_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
eth <- agesex %>% filter(`Country / territory of asylum/residence`=="Ethiopia")
eth <- pivot_longer(eth,
cols = c(3:12),
names_to = "agesex",
values_to = "refugees")
eth$agesex <- factor(eth$agesex, levels = c("Female 0-4", "Female 5-17", "Female 18-59", "Female 60+", "F: Unknown",
"Male 0-4", "Male 5-17", "Male 18-59", "Male 60+", "M: Unknown"))
eth_p <- ggplot(eth, aes(x=Year, y=refugees, fill=agesex)) + geom_area() + scale_fill_manual(values = colors) +
ggtitle("Age and Sex of Displaced in Ethiopia") + ylab("Refugees and Asylum Seekers") + theme(legend.title = element_blank())
ggplotly(eth_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
gtm <- agesex %>% filter(`Country / territory of asylum/residence`=="Guatemala")
gtm <- pivot_longer(gtm,
cols = c(3:12),
names_to = "agesex",
values_to = "refugees")
gtm$agesex <- factor(gtm$agesex, levels = c("Female 0-4", "Female 5-17", "Female 18-59", "Female 60+", "F: Unknown",
"Male 0-4", "Male 5-17", "Male 18-59", "Male 60+", "M: Unknown"))
gtm_p <- ggplot(gtm, aes(x=Year, y=refugees, fill=agesex)) + geom_area() + scale_fill_manual(values = colors) +
ggtitle("Age and Sex of Displaced in Guatemala") + ylab("Refugees and Asylum Seekers") + theme(legend.title = element_blank())
ggplotly(gtm_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
irq <- agesex %>% filter(`Country / territory of asylum/residence`=="Iraq")
irq <- pivot_longer(irq,
cols = c(3:12),
names_to = "agesex",
values_to = "refugees")
irq$agesex <- factor(irq$agesex, levels = c("Female 0-4", "Female 5-17", "Female 18-59", "Female 60+", "F: Unknown",
"Male 0-4", "Male 5-17", "Male 18-59", "Male 60+", "M: Unknown"))
irq_p <- ggplot(irq, aes(x=Year, y=refugees, fill=agesex)) + geom_area() + scale_fill_manual(values = colors) +
ggtitle("Age and Sex of Displaced in Iraq") + ylab("Refugees and Asylum Seekers") + theme(legend.title = element_blank())
ggplotly(irq_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
lby <- agesex %>% filter(`Country / territory of asylum/residence`=="Libya")
lby <- pivot_longer(lby,
cols = c(3:12),
names_to = "agesex",
values_to = "refugees")
lby$agesex <- factor(lby$agesex, levels = c("Female 0-4", "Female 5-17", "Female 18-59", "Female 60+", "F: Unknown",
"Male 0-4", "Male 5-17", "Male 18-59", "Male 60+", "M: Unknown"))
lby_p <- ggplot(lby, aes(x=Year, y=refugees, fill=agesex)) + geom_area() + scale_fill_manual(values = colors) +
ggtitle("Age and Sex of Displaced in Lybia") + ylab("Refugees and Asylum Seekers") + theme(legend.title = element_blank())
ggplotly(lby_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
mli <- agesex %>% filter(`Country / territory of asylum/residence`=="Mali")
mli <- pivot_longer(mli,
cols = c(3:12),
names_to = "agesex",
values_to = "refugees")
mli$agesex <- factor(mli$agesex, levels = c("Female 0-4", "Female 5-17", "Female 18-59", "Female 60+", "F: Unknown",
"Male 0-4", "Male 5-17", "Male 18-59", "Male 60+", "M: Unknown"))
mli_p <- ggplot(mli, aes(x=Year, y=refugees, fill=agesex)) + geom_area() + scale_fill_manual(values = colors) +
ggtitle("Age and Sex of Displaced in Mali") + ylab("Refugees and Asylum Seekers") + theme(legend.title = element_blank())
ggplotly(mli_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
mmr <- agesex %>% filter(`Country / territory of asylum/residence`=="Myanmar")
mmr <- pivot_longer(mmr,
cols = c(3:12),
names_to = "agesex",
values_to = "refugees")
mmr$agesex <- factor(mmr$agesex, levels = c("Female 0-4", "Female 5-17", "Female 18-59", "Female 60+", "F: Unknown",
"Male 0-4", "Male 5-17", "Male 18-59", "Male 60+", "M: Unknown"))
mmr_p <- ggplot(mmr, aes(x=Year, y=refugees, fill=agesex)) + geom_area() + scale_fill_manual(values = colors) +
ggtitle("Age and Sex of Displaced in Myanmar") + ylab("Refugees and Asylum Seekers") + theme(legend.title = element_blank())
ggplotly(mmr_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
nga <- agesex %>% filter(`Country / territory of asylum/residence`=="Nigeria")
nga <- pivot_longer(nga,
cols = c(3:12),
names_to = "agesex",
values_to = "refugees")
nga$agesex <- factor(nga$agesex, levels = c("Female 0-4", "Female 5-17", "Female 18-59", "Female 60+", "F: Unknown",
"Male 0-4", "Male 5-17", "Male 18-59", "Male 60+", "M: Unknown"))
nga_p <- ggplot(nga, aes(x=Year, y=refugees, fill=agesex)) + geom_area() + scale_fill_manual(values = colors) +
ggtitle("Age and Sex of Displaced in Nigeria") + ylab("Refugees and Asylum Seekers") + theme(legend.title = element_blank())
ggplotly(nga_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
syr <- agesex %>% filter(`Country / territory of asylum/residence`=="Syrian Arab Rep.")
syr <- pivot_longer(syr,
cols = c(3:12),
names_to = "agesex",
values_to = "refugees")
syr$agesex <- factor(syr$agesex, levels = c("Female 0-4", "Female 5-17", "Female 18-59", "Female 60+", "F: Unknown",
"Male 0-4", "Male 5-17", "Male 18-59", "Male 60+", "M: Unknown"))
syr_p <- ggplot(syr, aes(x=Year, y=refugees, fill=agesex)) + geom_area() + scale_fill_manual(values = colors) +
ggtitle("Age and Sex of Displaced in Syria") + ylab("Refugees and Asylum Seekers") + theme(legend.title = element_blank())
ggplotly(syr_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
sdn <- agesex %>% filter(`Country / territory of asylum/residence`=="Sudan")
sdn <- pivot_longer(sdn,
cols = c(3:12),
names_to = "agesex",
values_to = "refugees")
sdn$agesex <- factor(sdn$agesex, levels = c("Female 0-4", "Female 5-17", "Female 18-59", "Female 60+", "F: Unknown",
"Male 0-4", "Male 5-17", "Male 18-59", "Male 60+", "M: Unknown"))
sdn_p <- ggplot(sdn, aes(x=Year, y=refugees, fill=agesex)) + geom_area() + scale_fill_manual(values = colors) +
ggtitle("Age and Sex of Displaced in Sudan") + ylab("Refugees and Asylum Seekers") + theme(legend.title = element_blank())
ggplotly(sdn_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
ssd <- agesex %>% filter(`Country / territory of asylum/residence`=="South Sudan")
ssd <- pivot_longer(ssd,
cols = c(3:12),
names_to = "agesex",
values_to = "refugees")
ssd$agesex <- factor(ssd$agesex, levels = c("Female 0-4", "Female 5-17", "Female 18-59", "Female 60+", "F: Unknown",
"Male 0-4", "Male 5-17", "Male 18-59", "Male 60+", "M: Unknown"))
ssd_p <- ggplot(ssd, aes(x=Year, y=refugees, fill=agesex)) + geom_area() + scale_fill_manual(values = colors) +
ggtitle("Age and Sex of Displaced in South Sudan") + ylab("Refugees and Asylum Seekers") + theme(legend.title = element_blank())
ggplotly(ssd_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
som <- agesex %>% filter(`Country / territory of asylum/residence`=="Somalia")
som <- pivot_longer(som,
cols = c(3:12),
names_to = "agesex",
values_to = "refugees")
som$agesex <- factor(som$agesex, levels = c("Female 0-4", "Female 5-17", "Female 18-59", "Female 60+", "F: Unknown",
"Male 0-4", "Male 5-17", "Male 18-59", "Male 60+", "M: Unknown"))
som_p <- ggplot(som, aes(x=Year, y=refugees, fill=agesex)) + geom_area() + scale_fill_manual(values = colors) +
ggtitle("Age and Sex of Displaced in Somalia") + ylab("Refugees and Asylum Seekers") + theme(legend.title = element_blank())
ggplotly(som_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
ven <- agesex %>% filter(`Country / territory of asylum/residence`=="Venezuela (Bolivarian Republic of)")
ven <- pivot_longer(ven,
cols = c(3:12),
names_to = "agesex",
values_to = "refugees")
ven$agesex <- factor(ven$agesex, levels = c("Female 0-4", "Female 5-17", "Female 18-59", "Female 60+", "F: Unknown",
"Male 0-4", "Male 5-17", "Male 18-59", "Male 60+", "M: Unknown"))
ven_p <- ggplot(ven, aes(x=Year, y=refugees, fill=agesex)) + geom_area() + scale_fill_manual(values = colors) +
ggtitle("Age and Sex of Displaced in Venezuela") + ylab("Refugees and Asylum Seekers") + theme(legend.title = element_blank())
ggplotly(ven_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")
yem <- agesex %>% filter(`Country / territory of asylum/residence`=="Yemen")
yem <- pivot_longer(yem,
cols = c(3:12),
names_to = "agesex",
values_to = "refugees")
yem$agesex <- factor(yem$agesex, levels = c("Female 0-4", "Female 5-17", "Female 18-59", "Female 60+", "F: Unknown",
"Male 0-4", "Male 5-17", "Male 18-59", "Male 60+", "M: Unknown"))
yem_p <- ggplot(yem, aes(x=Year, y=refugees, fill=agesex)) + geom_area() + scale_fill_manual(values = colors) +
ggtitle("Age and Sex of Displaced in Yemen") + ylab("Refugees and Asylum Seekers") + theme(legend.title = element_blank())
ggplotly(yem_p, dynamicTicks = TRUE) %>%
layout(hovermode = "x")